<?php
/**
 * Geneone: Content Management Framework
 * RDF Metadata Module: User
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
require_once 'XML/Tree.php';
 
class Gene_User_FOAF {
	/**
	 * Parses a FOAF file and returns information from it.
	 *
	 * @var string $str FOAF File
	 *
	 * @return array FOAF Data
	 */
	function parse($str) {
		$tree =& new XML_Tree();
		
		// Check data is well formed
		if (PEAR::isError($root =& $tree->getTreeFromString($str))) {
			return false;
		}
		
		if (PEAR::isError($data = @$root->getNodeAt("foaf:Person")) OR !count($data->children)) {
			return false;
		}
		
		$foafdata = array();
		foreach ($data->children as $j => $k) {
			if ($k->name and $k->content) {
				$k->name = str_replace(":", "_", $k->name);
				$k->content = str_replace('&apos;', '\'', $k->content);
				$foafdata[$k->name] = $k->content;
			}
		}
		
		return $foafdata;
	}
}
?>